<template>
<div class="rolePrivilege">
    <div class="btns">
        <el-form size="medium" inline style="text-align:center">
           <el-form-item label="角色ID" size="small" inline>
            <el-input v-model="param.roleId"></el-input>
        </el-form-item>
        <el-form-item label="权限ID" size="small" inline>
            <el-input v-model="param.privilegeId"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button  type="primary" size="small" icon="el-icon-search" @click="loadRolePrivilege">搜索</el-button>
        </el-form-item>  
            <el-form-item>
                <el-button type="primary" size="small" icon="el-icon-plus" @click="toAddHandler">添加</el-button>
            </el-form-item>
             <el-form-item>
                <el-button type="primary" size="small" icon="el-icon-download" @click="downloadHandler">导出</el-button>
            </el-form-item>
        </el-form>
    </div>
    <el-table border style="width : 200%" size="small" :data="rolePrivilege" :default-sort="{prop:'data',order:'ascending'}">
        <el-table-column type="index" :index="1" label="序号"></el-table-column>
        <el-table-column label="ID" prop="id" align="center"></el-table-column>
        <el-table-column label="角色ID" sortable prop="roleId" align="center"></el-table-column>
        <el-table-column label="权限ID" sortable prop="privilegeId" align="center"></el-table-column>
        <el-table-column label="操作" width="200px" align="center">
            <template slot-scope="scope">
                <el-button type="primary" size="mini" icon="el-icon-edit"  @click="editHandler(scope.row)">编辑</el-button>
                <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteHandler(scope.row)">删除</el-button>
            </template>        
        </el-table-column>
    </el-table>
</div>
</template>

<script>
import{del, get,post} from '@/utils/request'
export default {
//页面数据
 data(){
     return {
         //参数，用于保存检索的参数
         param:{},
         //组件模板中需要的数据
         rolePrivilege:[]
     }
 },
//页面渲染的时候会调用的函数
 created(){
     this.loadRolePrivilege();
     console.log(this.$router);
 },
//所有的方法或者js的事件处理函数
 methods: {
     downloadHandler(){
         if(this.param.roleId){
      window.location.href = "http://39.106.31.187:8888/baseRolePrivilege/download?roleId="+this.param.roleId;
         }
         else if(this.param.privilegeId){
      window.location.href = "http://39.106.31.187:8888/baseRolePrivilege/download?privilegeId="+this.param.privilegeId;
         }
      else {
        window.location.href = "http://39.106.31.187:8888/baseRolePrivilege/download"
      }
     },
     //修改事件处理函数
     editHandler(row){
         //跳转到修改页面(新增页面)
         //携带当前行数据
         this.$router.push({
             path:"/privilege/rolePrivilegeCreate",      //跳转的路由
             query:row     //携带的参数
         })
     },
     //删除事件处理函数
     deleteHandler(row){
         this.$confirm("此操作将永久删除该数据，是否继续？","提示",{
             confirmButtonText:"确定",
             cancelButtonText:"取消",
             type:"warning",
         }).then(()=>{
             let url="http://39.106.31.187:8888/baseRolePrivilege/deleteById"
             del(url,{id:row.id}).then((resp)=>{
                 this.$message({type:"success", message:resp.message});
                 this.loadRolePrivilege();
             });
         });
     },
     //跳转
     toAddHandler(){
         this.$router.push("/privilege/rolePrivilegeCreate")
     },
     //查询后台中的应用信息
     loadRolePrivilege(){
         let url = 'http://39.106.31.187:8888/baseRolePrivilege/query'
         get(url,this.param).then((resp)=>{
             this.rolePrivilege=resp.data;
         })
     }
 }
}
</script>

<style scoped>
.btns {
    margin-bottom: .5em;
}

</style>
